<?php
/*
Product Detail controller
*/


class adminAdDetailController extends appController
{
	function index()
	{
		
		
		$adDetail = $this -> adminAdDetail -> _getRowData("adsInfo", "*", "adID=".$this->data['aid']);
		$adImages = $this -> adminAdDetail -> _getRowData("adImages", "*", "adID=".$this->data['aid']);
		$adUserInfo = $this -> adminAdDetail -> _getRowData("usersInfo", "userName, userEmail", "userID=".$adDetail['userID']);
		
		$this->set("adDetail", $adDetail);
		$this->set("adImages", $adImages);
		$this->set("adUserInfo", $adUserInfo);
		


		$this -> render('Ad Detail');
	}
	
	function updateStatus(){
		
		if($this->data['status']=='Approved'){
			$fv = array("status"	=> "Approved");
			$where=array("adID" => $this->data['aid']);
			$rs = $this -> adminAdDetail -> _updateTable("adsInfo", $fv, $where);
		}
			
		if($this->data['status']=='Rejected'){
			$fv = array("status"	=> "Rejected");
			$where=array("adID" => $this->data['aid']);
			$rs = $this -> adminAdDetail -> _updateTable("adsInfo", $fv, $where);
		}

		if($this->data['status']=='Featured'){
			$fv = array("isFeatured"	=> 1);
			$where=array("adID" => $this->data['aid']);
			$rs = $this -> adminAdDetail -> _updateTable("adsInfo", $fv, $where);
		}
		    $message = "Your ad ".$this -> data['status'];
			$this -> sendNotifyEmail($this -> data['userEmail'], "Ad Status::".$_SERVER['HTTP_HOST'], $message);
			$redirect = array(	'page' => 'adManager');
			$this-> redirect($redirect);
		//echo $this->data['status'];
	}
	
	
}
?>